package com.example.boot6rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfigDdl {
    /*
     * 这个步骤就是往rabbitmq的broker里面创建一个队列
     * */
    @Bean(name = "dlmessage")
    public Queue queueMessage() {
        return new Queue("dl.message",true);
    }
    /*
     * 创建死信交换器
     * */
    @Bean(name = "dlexchange")
    public DirectExchange exchange() {
        return new DirectExchange("dl.exchange",true,false);
    }

    @Bean(name = "binding-dl")
    Binding bindingExchangeMessage(@Qualifier("dlmessage") Queue queueMessage,
                                   @Qualifier("dlexchange") DirectExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).
                with("dl");
    }
}
